<template>
    <div>
        <!-- 搜索 -->
        <el-form :inline="true" ref="params" size="small" :model="params" class="demo-form-inline" @submit.native.prevent>
            <el-form-item label="标题">
                <el-input @keyup.enter.native="onSubmit" v-model="params.title" clearable placeholder=""></el-input>
            </el-form-item>
             <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button @click="onReset">重置</el-button>
                <el-button type="primary" icon="el-icon-plus" @click="handleAdd('add')">新增功能说明</el-button>
                <el-button size="small" @click="batchDelete()" plain type="danger">批量删除</el-button>
            </el-form-item>
        </el-form>
        <el-table :row-key="getKey" :data="tableData" style="width: 100%" :header-cell-style="{ background: '#f0f2f5' }" ref="tableRef"
            @selection-change="changeSelect">
            <el-table-column type="selection" width="55" reserve-selection >
            </el-table-column>
            <el-table-column label="序号" type="index"></el-table-column>
            <el-table-column prop="title" label="标题"  width="190" show-overflow-tooltip>
            </el-table-column>
            <!-- <el-table-column prop="updateTime" label="创建时间" show-overflow-tooltip>
            </el-table-column> -->
            <el-table-column prop="remark" label="备注" width="300" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间"  width="190" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="updateTime" label="更新时间"  width="190" show-overflow-tooltip>
            </el-table-column>
           <el-table-column fixed="right" label="操作" width="120">
                <template slot-scope="scope">
                    <!-- <el-button @click="handleDetail(scope.row)" type="text" size="small">详情</el-button> -->
                    <el-button @click="handleEdit('edit', scope.row)" type="text" size="small">修改</el-button>
                    <el-button @click="hanldeDelete(scope.row.id)" type="text" size="small">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="poolPage">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="params.page" :page-sizes="[10, 20, 30]" :page-size="params.pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
        <specificationDialog @getTrain="getTrain" ref="formContent" />
         <!-- 用户详情

         <specificationDetail ref="speContent" /> -->
    </div>
</template>
<script>
import { specificationList, specificationDelete } from "@/request/api/specification"
import specificationDialog from "./specificationDialog.vue"
// import specificationDetail from "./specificationDetail.vue"

export default {
    components: {
        specificationDialog,
        // specificationDetail
    },
    data() {
        return {
            multipleSelection: [],//批量选择

            tableData: [],
            params: {
                page: 1,
                pageSize: 10,
                id:"",
                // title:"",//标题
                // text:"",//文本内容
                // remark:"",//备注
                // imgDtos:[]    //图片关联表
               
            },
            total: 0
        }
    },
    created() {
        this.getTrain()
    },
    methods: {
        // 获取列表
        getTrain() {
            specificationList(this.params, {}).then(res => {
                if (res.data.code === 200) {
                    this.tableData = res.data.result.items
                    this.total = res.data.result.total
                }
            })
        },
        // 搜索
        onSubmit() {
            this.params.page = 1;
            this.getTrain();
        },
        // 重置
        onReset() {
            let params = {
                page: 1,
                pageSize: 10,
                // name: '',//连接名称
                // lyTp:"",//路演中心图片
                title:"",//路演中心标题可作为筛选条件
                // text:"",//路演中心文本内容
                // remark:"",//备注
            }
            this.params = params
            this.getTrain();
        },
        handleSizeChange(val) {
            this.params.pageSize = val;
            this.params.page = 1;
            this.getTrain();
        },

        handleCurrentChange(val) {
            this.params.page = val;
            this.getTrain();
        },
        // 新增中心
        handleAdd(type, data) {
            this.$refs.formContent.open(type, data)
        },
        // 修改
        handleEdit(type, data) {
            this.$refs.formContent.open(type, data)
        },
        //  // 查看详情
        //  handleDetail(info){
        //     this.$refs.speContent.open(info)
        // },
        // 删除
        hanldeDelete(id) {
            this.$confirm("确定删除该条信息吗?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                
                specificationDelete(id).then((res) => {
                    if (res.data.code === 200) {
                        this.$message({
                            message: res.data.message,
                            type: "success",
                        });
                        this.getTrain()
                        this.$refs.tableRef.clearSelection();

                    } else {
                        this.$message.error(res.data.message);
                    }
                });
            })
        },
          // 选择左侧复选框
          changeSelect(val) {
            this.multipleSelection = val;
        },
        getKey(row) {
            return row.id;
        },
        // 批量删除
        batchDelete() {
            if (this.multipleSelection.length === 0) {
                this.$message({
                    message: '请选择数据！',
                    type: 'warning'
                });
                return false;
            }
            // this.$confirm("确定删除吗?", "提示", {
            //     confirmButtonText: "确定",
            //     cancelButtonText: "取消",
            //     type: "warning",
            // }).then(() => {
                var ids = this.multipleSelection.map(item => item.id)
                this.hanldeDelete(ids)
            // })
        },
    }
}
</script>
<style lang="less" scoped>
.poolPage {
    margin-top: 15px;
    text-align: right;
}
</style>

